package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.model.settlement.SettleSummary;
import com.tiancheng.trade.settlement.service.settlement.ISettleSummaryService;
import com.tiancheng.trade.settlement.service.settlement.SettleCheckService;
import com.tiancheng.trade.settlement.vo.settlement.admin.SettleMarkBatchVO;
import com.tiancheng.trade.settlement.vo.settlement.admin.SettleQueryVo;
import com.tiancheng.trade.settlement.vo.settlement.export.SettleExportAllQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;

/**
 * 收入成本报表
 *
 * @author lzh
 */
@RestController
@RequestMapping("/admin/settleSummary")
@Slf4j
public class SettleSummaryAdminController {

    @Autowired
    private ISettleSummaryService settleSummaryService;
    @Autowired
    private SettleCheckService settleCheckService;

    /**
     * 查询单个商户某天对账结果
     *
     * @param settleQueryVo
     * @return
     */
    @PostMapping("/querySettleSummaryOne")
    @Validated
    public Result<SettleSummary> querySettleSummaryOne(@RequestBody @Valid SettleQueryVo settleQueryVo) {
        return Result.success(settleSummaryService.querySettleSummaryOne(settleQueryVo));
    }

    /**
     * 对账结果列表获取
     *
     * @param settleQueryVo
     * @return
     */
    @PostMapping("/list")
    public Result<?> listSettleSummary(@RequestBody SettleQueryVo settleQueryVo) {
        return Result.success(settleSummaryService.listSettleSummary(settleQueryVo));
    }

    /**
     * 导出单个商户某天对账结果
     *
     * @param settleQueryVo
     * @return
     */
    @PostMapping("/exportOne")
    @Validated
    public void exportOne(@RequestBody @Valid SettleQueryVo settleQueryVo, HttpServletRequest request, HttpServletResponse response) throws Exception {
        settleSummaryService.exportByMerchant(settleQueryVo, request, response);
    }

    /**
     * 汇总导出商户
     *
     * @param settleExportAllQueryVo
     * @return
     */
    @PostMapping("/exportAll")
    @Validated
    public void exportAll(@RequestBody @Valid SettleExportAllQueryVo settleExportAllQueryVo, HttpServletRequest request, HttpServletResponse response) throws Exception {
        settleSummaryService.exportAll(settleExportAllQueryVo, request, response);
    }

    /**
     * 更新对账数据
     *
     * @param settleQueryVo
     * @return
     */
    @PutMapping("/")
    @Validated
    public Result<String> update(@RequestBody @Valid SettleQueryVo settleQueryVo) {
        return Result.success(settleCheckService.doUpdate(settleQueryVo));
    }

    /**
     * 批量备注
     *
     * @param markBatchVO
     * @return
     */
    @PostMapping("/markBatch")
    @Validated
    public Result<?> markBatch(@RequestBody @Valid SettleMarkBatchVO markBatchVO) {
        if (settleCheckService.markBatch(markBatchVO)) {
            return Result.success();
        }
        return Result.fail("");
    }
}
